package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SummaryTradingPointsBo;
import org.dromara.system.domain.bo.SysUserPointsRecordsBo;
import org.dromara.system.domain.bo.SysUserPurseBo;
import org.dromara.system.domain.vo.SummaryTradingPointsVo;
import org.dromara.system.domain.vo.SysUserPointsRecordsVo;
import org.dromara.system.service.ISysUserPointsRecordsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 【请填写功能名称】
 *
 * @author Lion Li
 * @date 2025-07-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userPointsRecords")
public class  SysUserPointsRecordsController extends BaseController {

    private final ISysUserPointsRecordsService sysUserPointsRecordsService;

    /**
     * 查询积分记录列表
     */
//    @SaCheckPermission("system:userPointsRecords:list")
    @GetMapping("/list")
    public TableDataInfo<SysUserPointsRecordsVo> list(SysUserPointsRecordsBo bo, PageQuery pageQuery) {
        return sysUserPointsRecordsService.queryPageList(bo, pageQuery);
    }

    /**
     * 列表
     */
//    @SaCheckPermission("system:userPointsRecords:queryPointsRecordsEnums")
    @GetMapping("/queryPointsRecordsEnums")
    public R<List<HashMap<String, Object>>> queryPointsRecordsEnums() {
        return R.ok(sysUserPointsRecordsService.queryPointsRecordsEnums());
    }

    /**
     * 导出积分记录列表
     */
//    @SaCheckPermission("system:userPointsRecords:export")
    @Log(title = "积分记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysUserPointsRecordsBo bo, HttpServletResponse response) {
        List<SysUserPointsRecordsVo> list = sysUserPointsRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", SysUserPointsRecordsVo.class, response);
    }

    /**
     * 获取积分记录详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:userPointsRecords:query")
    @GetMapping("/{id}")
    public R<SysUserPointsRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                             @PathVariable Long id) {
        return R.ok(sysUserPointsRecordsService.queryById(id));
    }

    /**
     * 新增积分记录
     */
//    @SaCheckPermission("system:userPointsRecords:add")
    @Log(title = "积分记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysUserPointsRecordsBo bo) {
        return toAjax(sysUserPointsRecordsService.insertByBo(bo));
    }

    /**
     * 修改积分记录
     */
//    @SaCheckPermission("system:userPointsRecords:edit")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysUserPointsRecordsBo bo) {
        return toAjax(sysUserPointsRecordsService.updateByBo(bo));
    }

    /**
     * 删除积分记录
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:userPointsRecords:remove")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysUserPointsRecordsService.deleteWithValidByIds(List.of(ids), true));
    }


//    @SaCheckPermission("system:userPointsRecords:updateUserPoints")
    @Log(title = "修改积分", businessType = BusinessType.INSERT)
    @PostMapping("/updateUserPoints")
    public R<Boolean> updateUserPoints(@RequestBody List<SysUserPurseBo> boList) {
        return R.ok(sysUserPointsRecordsService.updateUserPoints(boList));
    }




}
